#include <stdio.h>
#include "Save_Read_File.h"

static unsigned int currentMaxId = 0;

void loadMaxId(const char* filePath) {
    FILE* file = fopen(filePath, "r");
    if (file != NULL) {
        fscanf(file, "%d", &currentMaxId);
        fclose(file);
    }
}

void saveMaxId(const char* filePath) {
    FILE* file = fopen(filePath, "w");
    if (file != NULL) {
        fprintf(file, "%d", currentMaxId);
        fclose(file);
    }
}

int generateUniqueId(const char* filePath) {
    if (currentMaxId == 0) {
        loadMaxId(filePath);
    }
    currentMaxId++;
    saveMaxId(filePath);
    return currentMaxId;
}

int Get_id()
{
    return currentMaxId;
}
